﻿
namespace DotNetNuke.Modules.agPageAdmin
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;

    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Tabs;
    using AutoMapper;

    [EnableClientAccess()]
    public class PageService : DomainService
    {
        PortalSettings _portalSettings;
        
        public PageService()
        {
            // We want to use a custom View Model for RIA Services since TabInfo has properties with unsupported types.
            // This also allows us to use Data Annotations on our View Model.
            Mapper.CreateMap<TabInfo, PageInfo>();

            _portalSettings = PortalSettings.Current;
        }

        public IEnumerable<PageInfo> GetPages(Boolean includeHost)
        {
            return includeHost ?
                Mapper.Map<List<TabInfo>, IEnumerable<PageInfo>>(TabController.GetPortalTabs(Null.NullInteger, Null.NullInteger, false, true)) :
                Mapper.Map<List<TabInfo>, IEnumerable<PageInfo>>(TabController.GetPortalTabs(_portalSettings.PortalId, Null.NullInteger, false, true));             
        }

    }

}


